<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <title>Document</title>
</head>
<style>
    .box {
        width: 500px;
        height: 400px;
        border: 1px solid #000;
        position: relative;
        margin: auto;
        overflow: hidden;
        cursor: pointer;
    }

    .box ul,
    .box ol {
        list-style: none;
        padding: 0;
        margin: 0;
    }

    .box ul li {
        width: 500px;
        height: 400px;
        display: none;
    }

    .box ul li img {
        width: 500px;
        height: 400px;
    }

    .box ol {
        width: 120px;
        position: absolute;
        left: 50%;
        margin-left: -40px;
        bottom: 20px;
        height: 20px;
        background: #fff;
        display: flex;
        justify-content: space-evenly;
        padding: 10px 0;
        border-radius: 20px;
    }

    .box ol li {
        width: 20px;
        height: 20px;
        border-radius: 50%;
        background: #f00;
        border: 1px solid #999;
    }

    .box ol li.current {
        background: #00f;
    }

    .box ul li.current {
        display: block;
    }

    .box .left,
    .box .right {
        position: absolute;
        top: 50%;
        width: 30px;
        height: 30px;
        margin-top: -15px;
        background: #ccc;
        text-align: center;
        line-height: 30px;
        text-decoration: none;
        font-weight: bold;
        color: #fff;
    }

    .left {
        left: 0;
    }

    .right {
        right: 0;
    }
</style>

<body>
    <div class="box">
        <ul>
            <li class="current"><img src="images/1.jpg" alt=""></li>
            <li><img src="images/2.jpg" alt=""></li>
            <li><img src="images/3.jpg" alt=""></li>
            <li>
                <img src="images/4.jpg" alt="">
            </li>
        </ul>
        <ol>
            <li class="current"></li>
            <li></li>
            <li></li>
            <li></li>
        </ol>
        <a href="javascript:;" class="left">&lt;</a>
        <a href="javascript:;" class="right">&gt;</a>
    </div>
</body>
<script type="text/javascript">
    /*
        实现功能
        1、自动切换图片 保证小圆点跟随
        2、上一张下一张点击切换图片  小圆点也需要跟随
        3、点击小圆点 切换到对应的图片
    */
    let imgs = document.querySelectorAll('.box>ul>li');
    let tag = document.querySelectorAll('ol>li');
    let index = 0; //图片与圆点下标相同
    let timer;

    // play();
    function play() {
        timer = setInterval(function () {
            index++;
            index == 4 ? index = 0 : '';
            imgsRemove();
            tagRemove();
        }, 1000)
    }

    //左右按钮点击事件
    document.querySelector('.left').addEventListener('click', function () {
        index--;
        index < 0 ? index = 3 : '';
        imgsRemove();
        tagRemove();
    })
    document.querySelector('.right').addEventListener('click', function () {
        index++;
        index > 3 ? index = 0 : '';
        imgsRemove();
        tagRemove();
    })

    //鼠标移入移出事件
    let box = document.querySelector('.box');
    box.onmouseover = () => clearInterval(timer);
    box.onmouseout = () => play();


    //类名排他
    function imgsRemove() {
        imgs.forEach(function (item) {
            item.className = '';
        })
        imgs[index].className = 'current';
    }
    function tagRemove() {
        tag.forEach(function (item) {
            item.className = '';
        })
        tag[index].className = 'current';
    }


</script>

</html>


       fn(arr)
    </script>
</body>
</html>